﻿
namespace Traceability.Infrastructure
{
    public class BaseRepository<T> : IBaseRepository<T> where T : class
    {
        private readonly DataDbContext dbContext;

        public BaseRepository(DataDbContext dbContext)
        {
            this.dbContext = dbContext;
        }

        public async Task<int> Add(T t)
        {
            await dbContext.Set<T>().AddAsync(t);
            return await dbContext.SaveChangesAsync();
        }

        public async Task<int> Del(T t)
        {
            dbContext.Set<T>().Remove(t);
            return await dbContext.SaveChangesAsync();
        }

        public IQueryable<T> GetAll()
        {
            return dbContext.Set<T>().AsQueryable();
        }

        public async Task<int> UpdAllAsync(List<T> t)
        {
            dbContext.Set<T>().UpdateRange(t);
            return await dbContext.SaveChangesAsync();
        }

        public async Task<int> Update(T t)
        {
            dbContext.Set<T>().Update(t);
            return await dbContext.SaveChangesAsync();
        }
    }
}